package com.cljz.peipei.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.cljz.peipei.R;
import com.cljz.peipei.base.App;
import com.cljz.peipei.base.BaseActivity;
import com.cljz.peipei.model.net.bean.UserSetBean;
import com.cljz.peipei.present.activity.SetUserP;
import com.cljz.peipei.utils.T;
import com.jakewharton.rxbinding.view.RxView;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.router.Router;
import rx.functions.Action1;

/**
 * Created by apple on 2017/4/18.
 */

public class SetNicknameActivity extends BaseActivity<SetUserP> {

    @BindView(R.id.fl_back)
    FrameLayout flBack;
    @BindView(R.id.tv_your_name)
    TextView tvYourName;
    @BindView(R.id.et_nickname)
    EditText etNickname;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    private Bundle bundle;

    @Override
    public void initData(Bundle savedInstanceState) {
        bundle = getIntent().getExtras();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_set_nickname;
    }

    @Override
    protected void initListener() {
        super.initListener();
        RxView.clicks(flBack)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Router.pop(SetNicknameActivity.this);
                    }
                });
        RxView.clicks(btnSubmit)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        String nickname = etNickname.getText().toString().trim();
                        if (!"".equals(nickname)) {
                            getP().userSet(bundle.getString("sex"), bundle.getString("age"), nickname);
                        } else {
                            T.getInstance().showShort("昵称不能为空");
                        }
                    }
                });
    }

    @Override
    public SetUserP newP() {
        return new SetUserP();
    }

    public void setUserSucceed(UserSetBean userSetBean) {
        Router.newIntent((Activity) App.getInstance())
                .to(MainActivity.class)
                .launch();
        com.cljz.peipei.utils.ActivityManager.getInstance().finishAfterActivity(MainActivity.class);
    }

    public void setUserFail(String error) {

    }
}
